﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using TempEmployees.DAL;
using TempEmployees.BLL.Database;

namespace TempEmployees.BLL.UserAccess
{
    public class DebugLoginService : ILoginService
    {
        public IUserDetails Logon(string username, string password)
        {
            var users = DbQuery.Database.Users.Where((u) => u.Username == username && u.Password == password);
            if (users.Count() != 1) throw new LoginErrorException("שם משתמש או סיסמא שגוים");
            var user = users.First();

            IUserDetails details = UserDetailsGenerator.GenerateUserDetails(user.ID);
            details.SetFirstName(user.FirstName);
            details.SetLastName(user.LastName);
            details.SetRoles(user.Roles);
            if (user.UserDepartments.Count > 0) details.SetDepartmentID(user.UserDepartments.First().ID);

            return details;
        }
    }
}